package udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class ReceiveByUDP {
    public static void main(String[] args) throws Exception {
        //创建对象
        DatagramSocket datagramSocket = new DatagramSocket(10088);
        //准备接受数据
        byte[] bytes = new byte[1024];
        DatagramPacket datagramPacket = new DatagramPacket(bytes, bytes.length);
    while (true) {
        //接受数据
        datagramSocket.receive(datagramPacket);
        //解析数据
        byte[] data = datagramPacket.getData();
        String s = new String(data, 0, datagramPacket.getLength());
        System.out.println(s);
         }
    }
}
